# 56. 绘图机器
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
let lines = [];
let n = 0;
let e = 0;
rl.on('line', function(line) {
lines.push(line);
if (lines.length === 1) {
[n, e] = line.split(' ').map(Number);
if (e === 0) {
console.log(0);
return;
}
}
if (e !== 0 && n !== 0 && lines.length === n+1) {
lines.shift();
const offsets = new Array(e).fill(0);
for(const line of lines) {
const [x, offsetY] = line.split(' ').map(Number);
offsets[x] = offsetY;
}
const dp = new Array(e).fill(0);
dp[0] = offsets[0];
for(let i=1; i<e; i++) {
dp[i] = dp[i-1] + offset[i];
}
let ans = 0;
for(const num of dp) {
ans += Math.abs(num);
}
console.log(ans);
}
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
← 55. 虚拟游戏理财 57. 机场航班调度 →